/*
 * net_event.h
 *
 *  Created on: 2012-7-5
 *      Author: ThinkPad
 */

#ifndef NET_EVENT_H_
#define NET_EVENT_H_


#include "smart_lock.h"

/*event enum type*/
enum EVENT
{
        EVENT_INVALID,
        EVENT_NEW_CONNECTION,
        EVENT_RECV,
        EVENT_RECV_COMPLETE,
        EVENT_SEND,
        EVENT_SEND_COMPLETE,
        EVENT_TRANS,
        EVENT_TRANS_COMPLETE,
        EVENT_CLIENT_ERROR,
        EVENT_CLIENT_CLOSED
};
/*event queue list node*/
struct io_event
{
        EVENT                io_evt;                 /*event type*/
        void                    *p_conn;                /*conn object*/
};

using namespace std;
class net_event
{
public:
        net_event(void);
        ~net_event(void);
        int init_queue(int size = DFLT_MIN_CONN_SIZ);
        int event_enqueue(EVENT io_evt,void *pcon);
        int event_dequeue(EVENT *evt,void **pcon);
        int get_event_count(void);

protected:
       int  add_event_queue_pool();

private:
       int event_queue_size;  /*default event queue size*/
       io_event * op_event;
	   stack<io_event *> free_queue;
	   queue<io_event *> event_queue;
	   smart_lock   evt_lock;
};


#endif /* NET_EVENT_H_ */
